import React, {Component} from 'react';
import './style.scss'
import {NavBar, Icon} from 'antd-mobile';

class StatusComponent extends Component {
    status = [
        {
            key: 1,
            value: '绑卡注册'
        },
        {
            key: 2,
            value: '绑定银行卡'
        },
        {
            key: 3,
            value: '修改密码'
        },
        {
            key: 4,
            value: '充值'
        },
        {
            key: 5,
            value: '提现'
        },
        {
            key: 6,
            value: '投资购买'
        },
        {
            key: 7,
            value: '用户授权'
        },
    ];

    backs() {
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        if (isAndroid) {
            android.back()
        } else {
            var message = {"method": "back"};
            window.webkit.messageHandlers.ios.postMessage(message);
        }
    }


    gogo(val) {
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        if (isAndroid) {
            android.goInvestor(val)
        } else {
            var message = {"method": val};
            window.webkit.messageHandlers.ios.postMessage(message);
        }
    }

    starts(val) {
        var u = navigator.userAgent;
        var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
        if (isAndroid) {
            android.start(val)
        } else {
            var message = {"method": val};
            window.webkit.messageHandlers.ios.postMessage(message);
        }
    }

    constructor(props) {
        super(props)
        let type = Number(window.location.hash.split('type=')[1])
        let text = '';
        this.status.forEach((item) => {
            if (item.key === type) {
                text = item.value;
            }
        });
    }

    render() {
        let type = Number(window.location.hash.split('type=')[1])
        let text = '';
        let success = true
        console.log(window.location);
        if (type === 99) {
            success = false
            console.log(123);
        } else {

            this.status.forEach((item) => {
                if (item.key === type) {
                    text = item.value;
                }
            });
        }
        const baseBtn = [<span className="hasPro" onClick={() => {
            this.gogo('backInvestor0')
        }}>去出借</span>,
            <span className="back" onClick={() => {
                this.gogo('backMine')
            }}>查看我的账户</span>]
        return (
            <div className="loanSuccess">
                <NavBar mode="light" className='title'>{text}</NavBar>
                <div className="contents">
                    <div className='status'>
                        <img src={success?require('../../assets/img/WechatIMG6.png'):require('../../assets/img/fail.png')} alt=""/>
                    </div>
                    <div className="tips">{success?`恭喜您${text}成功！`:'操作失败'}</div>
                    {type === 1 ?
                        [<span className="hasPro" onClick={() => {
                            this.backs()
                        }}>去逛逛</span>,
                            <span className="back" onClick={() => {
                                this.starts('recharge')
                            }}>去充值</span>] : ""} {/*个人绑卡注册*/}
                    {type === 2 ?
                        [<span className="hasPro" onClick={() => {
                            this.backs()
                        }}>返回</span>,
                            <span className="back" onClick={() => {
                                this.backs()
                            }}>完成</span>] : ""} {/*绑定银行卡*/}
                    {type === 3 ?
                        [<span className="hasPro" onClick={() => {
                            this.backs()
                        }}>返回</span>,
                            <span className="back" onClick={() => {
                                this.backs()
                            }}>完成</span>] : ""} {/*修改密码*/}
                    {type === 4 ? baseBtn : ""}{/*充值*/}
                    {type === 5 ?
                        [<span className="hasPro" onClick={() => {
                            this.gogo('backInvestor0')
                        }}>去逛逛</span>,
                            <span className="back" onClick={() => {
                                this.gogo('backMine')
                            }}>查看我的账户</span>] : ""}{/*提现*/}
                    {type === 6 ?
                        [
                            <span className="hasPro" onClick={() => {
                                this.starts('lending')
                            }}>查看已投项目</span>,
                            <span className="back" onClick={() => {
                                this.gogo('backInvestor0')
                            }}>返回精选项目</span>] : ''}{/*投资购买*/}
                    {type === 7 ?
                        [
                            <span className="hasPro" onClick={() => {
                                this.gogo('backInvestor0')
                            }}>查看精选项目</span>,
                            <span className="back" onClick={() => {
                                this.gogo('backMine')
                            }}>查看我的账户</span>] : ''}{/*用户授权*/}
                    <p className='warning'>网贷有风险，出借需谨慎</p>
                </div>
            </div>
        );
    }
}


export default StatusComponent
